﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Configuration;
using ServeNHL.Helpers;

namespace ServeNHL.Models
{
    public class UserSecurityViewModelcs
    {
        public USER user { get; set; }
        public List<USER_ROLE> roles { get; set; }

        /**
         * <summary>Checks the username/password to against the database</summary> 
         * <param name="username"></param>
         * <param name="password"></param>
         * <returns></returns>
         **/
        public Boolean isValidUser (string username, string password)
        {
            var isValid = false;
            String hashedPassword = "";

            using (var dbconn = new fclick_dbEntities())
            {
                hashedPassword = Helpers.UserHelper.getPasswordSaltHash(password);
                var user = dbconn.USERs.Where(u => u.USERNAME == username && u.PASSWORD == hashedPassword).FirstOrDefault();
                isValid = (user != null);

            }       // end of using (var dbconn = new fclick_dbEntities())

            return isValid;
        }       // end of public Boolean isValidUser (string username, string password)
    }       // end of class UserSecurityViewModelcs
}           // end of namespace ServeNHL.Models
